<template>
	<view>
		<view class="content bg-white margin-top">
			<view class="flex solid-bottom padding justify-start">
				<view class=" padding-sm radius">评分</view>
				<view class=" padding-sm  radius">
					<sx-rate :value="4" :fontSize="fontSize" :value.sync="rateSync" @change="onChange" />
				</view>
			</view>
			<view class="cu-form-group padding align-start">
				<view class="title padding-left-sm">评价</view>
				<textarea maxlength="200" v-model="context" placeholder="请填写评价"></textarea>
			</view>

			<view class="flex flex-direction margin">
				<button class="cu-btn bg-red margin-tb-sm lg" @click="submitAppraiseappraise()">评价</button>
			</view>

		</view>
	</view>
</template>

<script>

	import SxRate from '@/components/sx-rate'

	import {appraise} from '../../api/appraise/appraiseApi.js'
	export default {
		data() {
			return {
				fontSize:'60upx',
				rateSync: 2,
				animation: true,
				curAppraise: 4,
				context: '',
				shopId:'',
				cartId:'',
				productId:'',
				userId:'',
				userName:'',
				objType:''
			}
		},
		components: {
			SxRate
		},
	 async onLoad(options) {
		 await this.vc.onLoad(options).then(_suc=>{},_err=>{});
			let _that = this;
			this.productId = options.productId;
			this.objType = options.objType;
			this.cartId = options.cartId;
			this.shopId = options.shopId;
		},
		methods: {
			onChange(e) {
				this.curAppraise = e;
			},
			submitAppraiseappraise:function(){
				if(this.context == ''){
					uni.showToast({
						title:'请填写评价内容',
						icon:'none'
					});
					return ;
				}
				appraise({
					"parentAppraiseId":'-1',
					"shopId":this.shopId,
					 "context":this.context,
					 "appraiseUserId":this.vc.getCurrentUser().userId,
					 "appraiseUserName":this.vc.getCurrentUser().userName,
					 "appraiseScore":this.curAppraise,
					 "objId":this.productId,
					 "objType": this.objType,
					 "cartId":this.cartId
				})
				.then((_data)=>{
					wx.showToast({
						title: '成功',
						icon: 'none',
						duration: 2000
					});
					wx.hideLoading();
					uni.navigateBack({
						delta: 1
					});
				},(error)=>{
					wx.showToast({
						title: error,
						icon: 'none',
						duration: 2000
					});
				});
			}
		}
	}
</script>

<style>
	.content {
		height: 100%;
	}
</style>
